const gulp = require("gulp");
require('dotenv').config();
const GulpSSH = require("gulp-ssh");
const viteData = {
  development: { SERVICE_URL: `/mnt/koa/src/` },
};
const host =["120.26.80.19"]
// 需要上传到服务器的路径
const uploadData = [];
const shellData = [];
host.map((item) => {
  const config = {
    ssh: {
      host: item,
      port: 22,
      username: "root",
      password: "Becauseofyou10",
    },
  };
  const gulpSSH = new GulpSSH({
    ignoreErrors: false,
    sshConfig: config.ssh,
  });
  function name() {
    return gulp
      .src(`./src/**`)
      .pipe(gulpSSH.dest(viteData[process.env.NODE_ENV].SERVICE_URL));
  }
  function shell(type) {
    return gulpSSH.shell(`rm -rf ${viteData[process.env.NODE_ENV].SERVICE_URL}/assets/**${type}**`);
  }
  shellData.push(shell);
  uploadData.push(name);
});
// 不删除服务器代码 单上传
gulp.task("deploy", gulp.series(...uploadData));
